﻿define(function (require, exports, module) {

    String.Format = function () {
        for (var e = arguments[0], d = 0; d < arguments.length - 1; d++)
            e = e.replace(RegExp("\\{" + d + "\\}", "gm"), arguments[d + 1]);
        return e;
    };

    function trim(str) {
        //删除左右两端的空格
        return str.replace(/(^\s*)|(\s*$)/g, "");
    }

    function XMLStrToString(xmlStr) {
        var ret = xmlStr;
        ret = ret.replace(/&amp;/g, "&");
        ret = ret.replace(/&lt;/g, "<");
        ret = ret.replace(/&gt;/g, ">");
        ret = ret.replace(/&apos;/g, "\'");
        ret = ret.replace(/&quot;/g, "\"");
        ret = ret.replace(/\r/g, "");
        ret = ret.replace(/\n/g, " ");
        return ret;
    }

    function StringToXMLStr(Str) {
        var ret = Str;
        ret = ret.replace(/&/g, "&amp;");
        ret = ret.replace(/</g, "&lt;");
        ret = ret.replace(/>/g, "&gt;");
        ret = ret.replace(/\'/g, "&apos;");
        ret = ret.replace(/\"/g, "&quot;");
        return ret;
    }

    function GetNodeFloat(jqery_obj, item_name) {
        var ret = 0;
        if (jqery_obj && (typeof (jqery_obj.attr(item_name)) != "undefined")) {
            ret = parseFloat(jqery_obj.attr(item_name));
        }
        return ret;
    }

    function GetNodeString(jqery_obj, item_name) {
        var ret = "";
        if (jqery_obj && (typeof (jqery_obj.attr(item_name)) != "undefined")) {
            ret = XMLStrToString(jqery_obj.attr(item_name));
        }
        return ret;
    }

    FXREADER.GetNodeString = GetNodeString;
    FXREADER.GetNodeFloat = GetNodeFloat;

    function SetStyleLTWH(jqery_obj, l, t, w, h) {
        if (jqery_obj) {
            jqery_obj.css("left", l + "px").css("top", t + "px").css("width",
					w + "px").css("height", h + "px");
        }
    }
    ////////////////////////////////////////////解析及显示 Start
    var ConfigInfo = {
        PointToPx: (96.0 / 72.0)
    };

    var strFormatArr = {
        styleLTWH: "left:{0}px;top:{1}px;width:{2}px;height:{3}px;"
    };

    var Type =
    {
        Unknown: 0, 		// unsupported or invalid field. 
        PushButton: 1, 		// push button without any value. 
        RadioButton: 2, 	// a group of radio buttons, at most one item can be selected. 
        CheckBox: 3, 		// check box with on/off states. 
        Text: 4, 			// single line or multi-line texts. 
        RichText: 5, 		// rich text (using XML to store rich text). 
        File: 6, 			// file content. 
        ListBox: 7, 		// list box, single or multiple selections. 
        ComboBox: 8, 		// combo box with or without the edit box. 
        Sign: 9				// digital signature. 
    };

    function FloatRect() {
        this.top = 0;
        this.left = 0;
        this.width = 0;
        this.height = 0;

        this.SetValue = function (l, t, w, h) {
            this.left = l;
            this.top = t;
            this.width = w;
            this.height = h;
        };
    }

    function FormWidget() {
        this.strID = "";
        this.strBgID = "";
        this.strFgID = "";
        this.name = "";
        this.type = Type.Unknown;
        this.fieldAction = new Array();
        this.rect = new FloatRect();
        this.borderWidth = 0;
        this.fontSize = 12;
        this.bReadOnly = false;
        this.bRequired = false;
        this.curPageObj = null;

        this.Parse = function (id, node, curPageObj) {
            this.strID = id;
            this.strBgID = id + "_bg";
            this.strFgID = id + "_fg";
            this.curPageObj = curPageObj;
            if (node) {
                var self = this;
                if (this.curPageObj) {
                    node.children("Pos").each(function () {
                        self.rect = self.curPageObj.Transform(GetNodeFloat($(this), "l"), GetNodeFloat($(this), "b"), GetNodeFloat($(this), "w"), GetNodeFloat($(this), "h"));
                    });
                }

                node.children("General").each(function () {
                    $(this).children("ReadOnly").each(function () {
                        self.bReadOnly = trim($(this).text()) == "1" ? true : false;
                    });
                    $(this).children("Required").each(function () {
                        self.bRequired = trim($(this).text()) == "1" ? true : false;
                    });
                });

                node.children("Ap").each(function () {
                    $(this).children("Font").each(function () {
                        self.fontSize = GetNodeFloat($(this), "FontSize");
                    });
                    $(this).children("BS").each(function () {
                        $(this).children("W").each(function () {
                            self.borderWidth = parseFloat($(this).text());
                        });
                    });
                });

                this.name = GetNodeString(node, "Name");
                this.type = parseInt(GetNodeFloat(node, "Type"));

                node.children("AA").each(function () {
                    $(this).children().each(function () {
                        var ht_fildAAs = new Array();
                        var count = 0;
                        $(this).children().each(function () {
                            var value = XMLStrToString($(this).text());
                            if (value) {
                                ht_fildAAs[count++] = value;
                            }
                        });
                        self.fieldAction[$(this)[0].tagName] = ht_fildAAs;
                    });
                });
            }
        };

        this.GetControlID = function () {
            return this.strID;
        };

        this.GetRegisterActionCode = function () {
            if (!this.bReadOnly || this.type == Type.Text || this.type == Type.RichText) {
                for (key in this.fieldAction) {
                    var ht_aas = this.fieldAction[key];
                    for (var j = 0; j < ht_aas.length; j++) {
                        if (ht_aas[j]) {
                            $('#' + this.strID).AddActionJS(key, ht_aas[j]);
                        }
                    }
                }
            }
        };
    }

    //PushButton
    function FormWidget_PushBtn() {
        this.formWidget = new FormWidget();
        this.value = "";
        this.NImgPos = 0;
        this.RImgPos = 0;
        this.DImgPos = 0;

        this.Parser = function (id, node, curPageObj) {
            this.formWidget.Parse(id, node, curPageObj);
            if (node) {
                var self = this;
                node.children("Value").each(function () {
                    self.value = XMLStrToString($(this).text());
                });

                node.children("Ap").each(function () {
                    $(this).children("N").each(function () {
                        self.NImgPos = GetNodeFloat($(this), "Path");
                    });
                    $(this).children("R").each(function () {
                        self.RImgPos = GetNodeFloat($(this), "Path");
                    });
                    $(this).children("D").each(function () {
                        self.DImgPos = GetNodeFloat($(this), "Path");
                    });
                });
            }
        };

        this.GetControlID = function () {
            return this.formWidget.GetControlID();
        };

        this.GetHtmlCode = function (bHighlight) {
            var hideStyle = "display:none;";
            var divLeft = parseInt(this.formWidget.rect.left * ConfigInfo.PointToPx + 0.5);
            var divTop = parseInt(this.formWidget.rect.top * ConfigInfo.PointToPx + 0.5);
            var divWidth = parseInt(this.formWidget.rect.width * ConfigInfo.PointToPx + 0.5);
            var divHeight = parseInt(this.formWidget.rect.height * ConfigInfo.PointToPx + 0.5);
            var style_fg = String.Format(strFormatArr.styleLTWH + "position:absolute;padding:0;cursor:pointer;", divLeft, divTop, divWidth, divHeight);
            var style_bg = String.Format(strFormatArr.styleLTWH + "position:absolute;padding:0;cursor:pointer;", 0 - this.NImgPos, 0, this.formWidget.curPageObj.allImgWidth, this.formWidget.curPageObj.allImgHeight);
            var style_bgdiv = String.Format(strFormatArr.styleLTWH + "position:absolute;background-image:none;overflow:hidden;", divLeft, divTop, divWidth, divHeight);
            var strCode = String.Format("<div name='{0}'><div id='{1}' style='{2}'>", this.formWidget.name, this.formWidget.strBgID, style_bgdiv);
            strCode += String.Format("<img class='fwr_form_widget' tabindex=1 src='{0}' id='{1}' name='{2}' value='{3}'style='{4}'/>",
                            this.formWidget.curPageObj.m_imgUrl, this.GetControlID(), this.formWidget.name, this.value, style_bg);
            strCode += "</div>";
            if (!bHighlight || this.formWidget.bReadOnly) {
                style_fg += hideStyle;
            }
            strCode += String.Format("<div id='{0}' class='{1} fwr_form_widget' style='{2}'></div></div>", this.formWidget.strFgID, this.formWidget.bRequired ? "fwr_form_require_field_highlight" : "fwr_form_field_highlight", style_fg);
            return strCode;
        };

        this.GetReadyBindCode = function () {
            if (!this.formWidget.bReadOnly) {
                var controlid = this.GetControlID();
                var obj = $('#' + controlid);
                obj.bind('focus', { id: controlid, fgid: this.formWidget.strFgID }, PushButFocus);
                obj.bind('blur', { id: controlid, fgid: this.formWidget.strFgID }, PushButBlur);
                obj.bind('mouseout', { id: controlid, curPageNum: this.formWidget.curPageObj.m_iPageNum, nImgPos: this.NImgPos, rImgPos: this.RImgPos, dImgPos: this.DImgPos }, PushButMouseOut);
                obj.bind('mouseover', { id: controlid, curPageNum: this.formWidget.curPageObj.m_iPageNum, nImgPos: this.NImgPos, rImgPos: this.RImgPos, dImgPos: this.DImgPos }, PushButMouseOver);
                obj.bind('mousemove', { id: controlid, curPageNum: this.formWidget.curPageObj.m_iPageNum, nImgPos: this.NImgPos, rImgPos: this.RImgPos, dImgPos: this.DImgPos }, PushButMouseMove);
                obj.bind('mousedown', { id: controlid, curPageNum: this.formWidget.curPageObj.m_iPageNum, nImgPos: this.NImgPos, rImgPos: this.RImgPos, dImgPos: this.DImgPos }, PushButMouseDown);
                $('#' + this.formWidget.strFgID).bind('click', { id: controlid }, PushButFgClick);
            }
        };

        this.ChangeSize = function (scaleValue) {
            var divLeft = parseInt(this.formWidget.rect.left * ConfigInfo.PointToPx * scaleValue + 0.5);
            var divTop = parseInt(this.formWidget.rect.top * ConfigInfo.PointToPx * scaleValue + 0.5);
            var divWidth = parseInt(this.formWidget.rect.width * ConfigInfo.PointToPx * scaleValue + 0.5);
            var divHeight = parseInt(this.formWidget.rect.height * ConfigInfo.PointToPx * scaleValue + 0.5);
            SetStyleLTWH($("#" + this.formWidget.strBgID), divLeft, divTop, divWidth, divHeight);
            SetStyleLTWH($("#" + this.formWidget.strFgID), divLeft, divTop, divWidth, divHeight);

            var nImgLeft = 0 - parseInt(this.NImgPos * scaleValue + 0.5);
            var imgWidth = parseInt(this.formWidget.curPageObj.allImgWidth * scaleValue + 0.5);
            var imgHeight = parseInt(this.formWidget.curPageObj.allImgHeight * scaleValue + 0.5);
            SetStyleLTWH($("#" + this.GetControlID()), nImgLeft, 0, imgWidth, imgHeight);
        };

        this.ChangeHighlight = function (bHighlight) {
            if (!this.formWidget.bReadOnly) {
                $("#" + this.formWidget.strFgID).css("display", (bHighlight ? "" : "none"));

            }
           
        };

        this.ResetData = function () {
        };

        this.Update = function () {
        };
    }
    //Radio
    function FormWidget_Radio() {
        this.formWidget = new FormWidget();
        this.value = "";
        this.bCheck = false;
        this.bRadiosInUnison = false;
        this.bNoToggleToOff = true; //不可以取消选中项
        this.offImgPos = 0;
        this.onImgPos = 0;

        this.Parser = function (id, node, curPageObj) {
            this.formWidget.Parse(id, node, curPageObj);
            if (node) {
                var self = this;
                node.children("Value").each(function () {
                    self.value = XMLStrToString($(this).text());
                });

                node.children("State").each(function () {
                    $(this).children("Checked").each(function () {
                        self.bCheck = parseInt(GetNodeFloat($(this), "Checked")) > 0 ? true : false;
                    });
                    $(this).children("Unison").each(function () {
                        self.bRadiosInUnison = parseInt(GetNodeFloat($(this), "Unison")) > 0 ? true : false;
                    });
                });

                //获取bNoToggleToOff标志**待完善

                node.children("Ap").each(function () {
                    $(this).children("N").each(function () {
                        $(this).children("Off").each(function () {
                            self.offImgPos = GetNodeFloat($(this), "Path");
                        });

                        $(this).children("On").each(function () {
                            self.onImgPos = GetNodeFloat($(this), "Path");
                        });
                    });
                });

                if (typeof (FXREADER.g_formValue.GetItemValue(this.formWidget.name)) == "undefined") {
                    FXREADER.g_formValue.SetItemValue(this.formWidget.name, this.bCheck ? this.value : "Off");
                }
                else if (this.bCheck && FXREADER.g_formValue.GetItemValue(this.formWidget.name) == "Off") {
                    FXREADER.g_formValue.SetItemValue(this.formWidget.name, this.value);
                }
            }
        };

        this.GetControlID = function () {
            return this.formWidget.GetControlID();
        };

        this.GetHtmlCode = function (bHighlight) {
            var hideStyle = "display:none;";
            var divLeft = parseInt(this.formWidget.rect.left * ConfigInfo.PointToPx + 0.5);
            var divTop = parseInt(this.formWidget.rect.top * ConfigInfo.PointToPx + 0.5);
            var divWidth = parseInt(this.formWidget.rect.width * ConfigInfo.PointToPx + 0.5);
            var divHeight = parseInt(this.formWidget.rect.height * ConfigInfo.PointToPx + 0.5);
            var style_fg = String.Format(strFormatArr.styleLTWH + "position:absolute;padding:0;cursor:pointer;", divLeft, divTop, divWidth, divHeight);
            var style_bg = String.Format(strFormatArr.styleLTWH + "position:absolute;padding:0;cursor:pointer;", this.bCheck ? 0 - this.onImgPos : 0 - this.offImgPos, 0, this.formWidget.curPageObj.allImgWidth, this.formWidget.curPageObj.allImgHeight);
            var style_bgdiv = String.Format(strFormatArr.styleLTWH + "position:absolute;background-image:none;overflow:hidden;", divLeft, divTop, divWidth, divHeight);
            var strCode = String.Format("<div name='{0}'><div id='{1}' style='{2}'>", this.formWidget.name, this.formWidget.strBgID, style_bgdiv);
            strCode += String.Format("<img class='fwr_form_widget' tabindex=1 src='{0}' id='{1}' name='{2}' checked='{3}' value='{4}'style='{5}'/>",
                            this.formWidget.curPageObj.m_imgUrl, this.GetControlID(), this.formWidget.name, this.bCheck ? "1" : "0", this.value, style_bg);
            strCode += "</div>";
            if (!bHighlight || this.formWidget.bReadOnly) {
                style_fg += hideStyle;
            }
            strCode += String.Format("<div id='{0}' class='{1} fwr_form_widget' style='{2}'></div></div>", this.formWidget.strFgID, this.formWidget.bRequired ? "fwr_form_require_field_highlight" : "fwr_form_field_highlight", style_fg);
            return strCode;
        };

        this.GetReadyBindCode = function () {
            if (!this.formWidget.bReadOnly) {
                var controlid = this.GetControlID();
                var obj = $('#' + controlid);
                obj.bind('click', { id: controlid, bNoToggleToOff: this.bNoToggleToOff }, RaidoButClick);
                obj.bind('focus', { id: controlid, fgid: this.formWidget.strFgID }, CheckRaidoButFocus);
                obj.bind('blur', { id: controlid, fgid: this.formWidget.strFgID }, CheckRaidoButBlur);
                $('#' + this.formWidget.strFgID).bind('click', { id: controlid }, CheckRaidoButFgClick);
            }
        };

        this.ChangeSize = function (scaleValue) {
            var divLeft = parseInt(this.formWidget.rect.left * ConfigInfo.PointToPx * scaleValue + 0.5);
            var divTop = parseInt(this.formWidget.rect.top * ConfigInfo.PointToPx * scaleValue + 0.5);
            var divWidth = parseInt(this.formWidget.rect.width * ConfigInfo.PointToPx * scaleValue + 0.5);
            var divHeight = parseInt(this.formWidget.rect.height * ConfigInfo.PointToPx * scaleValue + 0.5);
            SetStyleLTWH($("#" + this.formWidget.strBgID), divLeft, divTop, divWidth, divHeight);
            SetStyleLTWH($("#" + this.formWidget.strFgID), divLeft, divTop, divWidth, divHeight);

            var imgLeft = this.offImgPos;
            var imgWidth = parseInt(this.formWidget.curPageObj.allImgWidth * scaleValue + 0.5);
            var imgHeight = parseInt(this.formWidget.curPageObj.allImgHeight * scaleValue + 0.5);
            if ($("#" + this.GetControlID()).attr("checked") == 1) {
                imgLeft = this.onImgPos;
            }
            imgLeft = 0 - parseInt(imgLeft * scaleValue + 0.5);
            SetStyleLTWH($("#" + this.GetControlID()), imgLeft, 0, imgWidth, imgHeight);
        };

        this.ChangeHighlight = function (bHighlight) {
            if (!this.formWidget.bReadOnly) {
                $("#" + this.formWidget.strFgID).css("display", (bHighlight ? "" : "none"));
            }
        };

        this.ResetData = function () {
            if (typeof (FXREADER.g_formValue.GetItemValue(this.formWidget.name)) == "undefined") {
                FXREADER.g_formValue.SetItemValue(this.formWidget.name, this.bCheck ? this.value : "Off");
            }
            else if (this.bCheck && FXREADER.g_formValue.GetItemValue(this.formWidget.name) == "Off") {
                FXREADER.g_formValue.SetItemValue(this.formWidget.name, this.value);
            }
            CheckedObj(this, this.bCheck);
        };

        this.Update = function () {
            var selectedItemID = arguments[0] ? arguments[0] : "";
            var value = FXREADER.g_formValue.GetItemValue(this.formWidget.name);
            var bCheck = false;
            if (typeof (value) != "undefined") {
                if (!selectedItemID || selectedItemID == "") {
                    selectedItemID = this.formWidget.curPageObj.GetRadioGroupSelectedItemID(this.formWidget.name);
                }

                bCheck = this.value == value;
                if (selectedItemID && selectedItemID != "" && (!this.bRadiosInUnison)) {
                    bCheck = bCheck && (selectedItemID == this.GetControlID());
                }
            }
            CheckedObj(this, bCheck);
        };
    }
    //Check
    function FormWidget_Check() {
        this.formWidget = new FormWidget();
        this.value = "";
        this.bCheck = false;
        this.offImgPos = 0;
        this.onImgPos = 0;

        this.Parser = function (id, node, curPageObj) {
            this.formWidget.Parse(id, node, curPageObj);
            if (node) {
                var self = this;
                node.children("Value").each(function () {
                    self.value = XMLStrToString($(this).text());
                });

                node.children("State").each(function () {
                    $(this).children("Checked").each(function () {
                        self.bCheck = parseInt(GetNodeFloat($(this), "Checked")) > 0 ? true : false;
                    });
                });

                node.children("Ap").each(function () {
                    $(this).children("N").each(function () {
                        $(this).children("Off").each(function () {
                            self.offImgPos = GetNodeFloat($(this), "Path");
                        });

                        $(this).children("On").each(function () {
                            self.onImgPos = GetNodeFloat($(this), "Path");
                        });
                    });
                });

                if (typeof (FXREADER.g_formValue.GetItemValue(this.formWidget.name)) == "undefined") {
                    FXREADER.g_formValue.SetItemValue(this.formWidget.name, this.bCheck ? this.value : "Off");
                }
                else if (this.bCheck && FXREADER.g_formValue.GetItemValue(this.formWidget.name) == "Off") {
                    FXREADER.g_formValue.SetItemValue(this.formWidget.name, this.value);
                }
            }
        };

        this.GetControlID = function () {
            return this.formWidget.GetControlID();
        };
        this.GetHtmlCode = function (bHighlight) {
            var hideStyle = "display:none;";
            var divLeft = parseInt(this.formWidget.rect.left * ConfigInfo.PointToPx + 0.5);
            var divTop = parseInt(this.formWidget.rect.top * ConfigInfo.PointToPx + 0.5);
            var divWidth = parseInt(this.formWidget.rect.width * ConfigInfo.PointToPx + 0.5);
            var divHeight = parseInt(this.formWidget.rect.height * ConfigInfo.PointToPx + 0.5);
            var style_fg = String.Format(strFormatArr.styleLTWH + "position:absolute;padding:0;cursor:pointer;", divLeft, divTop, divWidth, divHeight);
            var style_bg = String.Format(strFormatArr.styleLTWH + "position:absolute;padding:0;cursor:pointer;", this.bCheck ? 0 - this.onImgPos : 0 - this.offImgPos, 0, this.formWidget.curPageObj.allImgWidth, this.formWidget.curPageObj.allImgHeight);
            var style_bgdiv = String.Format(strFormatArr.styleLTWH + "position:absolute;background-image:none;overflow:hidden;", divLeft, divTop, divWidth, divHeight);
            var strCode = String.Format("<div name='{0}'><div id='{1}' style='{2}'>", this.formWidget.name, this.formWidget.strBgID, style_bgdiv);
            strCode += String.Format("<img class='fwr_form_widget' tabindex=1 src='{0}' id='{1}' name='{2}' checked='{3}' value='{4}'style='{5}'/>",
                            this.formWidget.curPageObj.m_imgUrl, this.GetControlID(), this.formWidget.name, this.bCheck ? "1" : "0", this.value, style_bg);
            strCode += "</div>";
            if (!bHighlight || this.formWidget.bReadOnly) {
                style_fg += hideStyle;
            }
            strCode += String.Format("<div id='{0}' class='{1} fwr_form_widget' style='{2}'></div></div>", this.formWidget.strFgID, this.formWidget.bRequired ? "fwr_form_require_field_highlight" : "fwr_form_field_highlight", style_fg);
            return strCode;
        };

        this.GetReadyBindCode = function () {
            if (!this.formWidget.bReadOnly) {
                var contolid = this.GetControlID();
                var obj = $('#' + contolid);
                obj.bind('click', { id: contolid }, CheckButClick);
                obj.bind('focus', { id: contolid, fgid: this.formWidget.strFgID }, CheckRaidoButFocus);
                obj.bind('blur', { id: contolid, fgid: this.formWidget.strFgID }, CheckRaidoButBlur);
                $('#' + this.formWidget.strFgID).bind('click', { id: contolid }, CheckRaidoButFgClick);
            }
        };

        this.ChangeSize = function (scaleValue) {
            var divLeft = parseInt(this.formWidget.rect.left * ConfigInfo.PointToPx * scaleValue + 0.5);
            var divTop = parseInt(this.formWidget.rect.top * ConfigInfo.PointToPx * scaleValue + 0.5);
            var divWidth = parseInt(this.formWidget.rect.width * ConfigInfo.PointToPx * scaleValue + 0.5);
            var divHeight = parseInt(this.formWidget.rect.height * ConfigInfo.PointToPx * scaleValue + 0.5);
            SetStyleLTWH($("#" + this.formWidget.strBgID), divLeft, divTop, divWidth, divHeight);
            SetStyleLTWH($("#" + this.formWidget.strFgID), divLeft, divTop, divWidth, divHeight);

            var imgLeft = this.offImgPos;
            var imgWidth = parseInt(this.formWidget.curPageObj.allImgWidth * scaleValue + 0.5);
            var imgHeight = parseInt(this.formWidget.curPageObj.allImgHeight * scaleValue + 0.5);
            if ($("#" + this.GetControlID()).attr("checked") == 1) {
                imgLeft = this.onImgPos;
            }
            imgLeft = 0 - parseInt(imgLeft * scaleValue + 0.5);
            SetStyleLTWH($("#" + this.GetControlID()), imgLeft, 0, imgWidth, imgHeight);
        };

        this.ChangeHighlight = function (bHighlight) {
            if (!this.formWidget.bReadOnly) {
                $("#" + this.formWidget.strFgID).css("display", (bHighlight ? "" : "none"));
            }

        };

        this.ResetData = function () {
            if (typeof (FXREADER.g_formValue.GetItemValue(this.formWidget.name)) == "undefined") {
                FXREADER.g_formValue.SetItemValue(this.formWidget.name, this.bCheck ? this.value : "Off");
            }
            else if (this.bCheck && FXREADER.g_formValue.GetItemValue(this.formWidget.name) == "Off") {
                FXREADER.g_formValue.SetItemValue(this.formWidget.name, this.value);
            }
            CheckedObj(this, this.bCheck);
        };

        this.Update = function () {
            var value = FXREADER.g_formValue.GetItemValue(this.formWidget.name);

            if (typeof (value) != "undefined") {
                var bCheck = this.value == value;
                CheckedObj(this, bCheck);
            }
        };
    }
    //Text
    function FormWidget_Text() {
        this.formWidget = new FormWidget();
        this.bMultiLine = false;
        this.bSpellCheck = false;
        this.imgPos = 0;
        this.value = "";

        this.bUnbind = true;

        this.Parser = function (id, node, curPageObj) {
            this.formWidget.Parse(id, node, curPageObj);
            if (this.formWidget.borderWidth == 0) {
                this.formWidget.borderWidth = 1;
            }
            if (node) {
                var self = this;
                node.children("Value").each(function () {
                    self.value = XMLStrToString($(this).text());
                });

                node.children("Flags").each(function () {
                    $(this).children("MultiLine").each(function () {
                        self.bMultiLine = trim($(this).text()) == "1" ? true : false;
                    });
                    $(this).children("SpellCheck").each(function () {
                        self.bSpellCheck = trim($(this).text()) == "1" ? true : false;
                    });
                });

                node.children("Ap").each(function () {
                    $(this).children("N").each(function () {
                        self.imgPos = GetNodeFloat($(this), "Path");
                    });
                });

                if (typeof (FXREADER.g_formValue.GetItemValue(this.formWidget.name)) == "undefined") {
                    FXREADER.g_formValue.SetItemValue(this.formWidget.name, this.value);
                }
            }
        };

        this.GetControlID = function () {
            return this.formWidget.GetControlID();
        };
        this.GetHtmlCode = function (bHighlight) {
            var divBgLeft = parseInt(this.formWidget.rect.left * ConfigInfo.PointToPx + 0.5);
            var divBgTop = parseInt(this.formWidget.rect.top * ConfigInfo.PointToPx + 0.5);
            var divBgWidth = parseInt(this.formWidget.rect.width * ConfigInfo.PointToPx + 0.5);
            var divBgHeight = parseInt(this.formWidget.rect.height * ConfigInfo.PointToPx + 0.5);
            var divBorderWidth = parseInt(this.formWidget.borderWidth * ConfigInfo.PointToPx + 0.5);
            var divLeft = divBgLeft + divBorderWidth;
            var divTop = divBgTop + divBorderWidth;
            var divWidth = divBgWidth - 2 * divBorderWidth;
            var divHeight = divBgHeight - 2 * divBorderWidth;
            var divFontSize = 0;
            if (this.formWidget.fontSize != -1) {
                divFontSize = parseInt(this.formWidget.fontSize * ConfigInfo.PointToPx + 0.5);
            }
            else {
                if (this.bMultiLine) {
                    divFontSize = parseInt(12 * ConfigInfo.PointToPx + 0.5);
                }
                else {
                    if (this.formWidget.curPageObj.rotate == 1 || this.formWidget.curPageObj.rotate == 3) {
                        divFontSize = parseInt(this.formWidget.rect.width * 0.7 * ConfigInfo.PointToPx + 0.5);
                    }
                    else {
                        divFontSize = parseInt(this.formWidget.rect.height * 0.7 * ConfigInfo.PointToPx + 0.5);
                    }
                }
            }
            var style_bg = String.Format(strFormatArr.styleLTWH + "position:absolute;padding:0;", 0 - this.imgPos, 0, this.formWidget.curPageObj.allImgWidth, this.formWidget.curPageObj.allImgHeight);
            var style_bgdiv = String.Format(strFormatArr.styleLTWH + "position:absolute;background-image:none;overflow:hidden;", divBgLeft, divBgTop, divBgWidth, divBgHeight);
            var strCode = String.Format("<div name='{0}'><div id='{1}' style='{2}'>",
                            this.formWidget.name, this.formWidget.strBgID + "_div", style_bgdiv);
            strCode += String.Format("<img class='fwr_form_widget' src='{0}' id='{1}' style='{2}'/>",
                            this.formWidget.curPageObj.m_imgUrl, this.formWidget.strBgID, style_bg);
            strCode += "</div>";

            if (this.bMultiLine) {
                var style = String.Format(strFormatArr.styleLTWH + "line-height:100%;max-width:{2}px;max-height:{3}px;position:absolute;background-image:url(about:blank);background-color:transparent;font-size:{4}px;resize:none;border:0;padding:0;",
                            divLeft, divTop, divWidth, divHeight, divFontSize);
                strCode += String.Format("<textarea id='{0}' name='{1}' style='{2}' class='fwr_form_textarea_none_border fwr_form_widget' multiline='1' {3}>{4}</textarea>",
                                this.GetControlID(), this.formWidget.name, style, this.formWidget.bReadOnly ? "readonly='readonly'" : "", this.value);
            }
            else {
                var style = String.Format(strFormatArr.styleLTWH + "line-height:{3}px;position:absolute;font-size:{4}px;background-image:url(about:blank);background-color:transparent;border:0;padding:0;",
                            divLeft, divTop, divWidth, divHeight, divFontSize);
                strCode += String.Format("<input type='text' class='fwr_form_widget' id='{0}' name='{1}' style='{2}' multiline='0' value='{3}' {4}/>",
                                this.GetControlID(), this.formWidget.name, style, this.value, this.formWidget.bReadOnly ? "readonly='readonly'" : "");
            }

            var style_fg = String.Format(strFormatArr.styleLTWH + "cursor:text;", divLeft, divTop, divWidth, divHeight);
            if (!bHighlight || this.formWidget.bReadOnly) {
                style_fg += "display:none";
            }
            strCode += String.Format("<div id='{0}' class='{1} fwr_form_widget' style='{2}'></div></div>", this.formWidget.strFgID, this.formWidget.bRequired ? "fwr_form_require_field_highlight" : "fwr_form_field_highlight", style_fg);
            return strCode;
        };

        this.GetReadyBindCode = function () {
            var controlid = this.GetControlID();
            var obj = $('#' + controlid);
            if (this.formWidget.bReadOnly) {
                if (this.bMultiLine) {
                    obj.bind('focus', { id: controlid, fgid: this.formWidget.strFgID, bReadOnly: this.formWidget.bReadOnly, bSpellCheck: this.bSpellCheck, bgid: this.formWidget.strBgID }, TextareaFocus);
                    obj.bind('blur', { id: controlid, fgid: this.formWidget.strFgID, bReadOnly: this.formWidget.bReadOnly, bgid: this.formWidget.strBgID }, TextareaBlur);
                }
            }
            else {
                if (this.bMultiLine) {
                    obj.bind('focus', { id: controlid, fgid: this.formWidget.strFgID, bReadOnly: this.formWidget.bReadOnly, bSpellCheck: this.bSpellCheck, bgid: this.formWidget.strBgID }, TextareaFocus);
                    obj.bind('blur', { id: controlid, fgid: this.formWidget.strFgID, bReadOnly: this.formWidget.bReadOnly, bgid: this.formWidget.strBgID }, TextareaBlur);
                }
                else {
                    obj.bind('focus', { id: controlid, fgid: this.formWidget.strFgID, bgid: this.formWidget.strBgID }, TextFocus);
                    obj.bind('blur', { id: controlid, fgid: this.formWidget.strFgID, bgid: this.formWidget.strBgID }, TextBlur);
                }
		        if (FXREADER.Environment.mobile || FXREADER.Environment.iOS) {
		            $('#' + this.formWidget.strFgID).bind('touchstart.jsp', { id: controlid }, FgClick);
		        }
                else
                $('#' + this.formWidget.strFgID).bind('click', { id: controlid }, FgClick);
                if (this.bSpellCheck) {
                    obj.bind('keypress', { id: controlid, bTextarea: this.bMultiLine }, TextSpellCeck);
                    obj.bind('paste', { id: controlid, bTextarea: this.bMultiLine }, TextPaste);
                }
            }
        };

        this.ChangeSize = function (scaleValue) {
            var divBgLeft = parseInt(this.formWidget.rect.left * ConfigInfo.PointToPx * scaleValue + 0.5);
            var divBgTop = parseInt(this.formWidget.rect.top * ConfigInfo.PointToPx * scaleValue + 0.5);
            var divBgWidth = parseInt(this.formWidget.rect.width * ConfigInfo.PointToPx * scaleValue + 0.5);
            var divBgHeight = parseInt(this.formWidget.rect.height * ConfigInfo.PointToPx * scaleValue + 0.5);
            var divBorderWidth = parseInt(this.formWidget.borderWidth * ConfigInfo.PointToPx * scaleValue + 0.5);
            var divLeft = divBgLeft + divBorderWidth;
            var divTop = divBgTop + divBorderWidth;
            var divWidth = divBgWidth - 2 * divBorderWidth;
            var divHeight = divBgHeight - 2 * divBorderWidth;
            var divFontSize = 0;
            if (this.formWidget.fontSize != -1) {
                divFontSize = parseInt(this.formWidget.fontSize * ConfigInfo.PointToPx * scaleValue + 0.5);
            }
            else {
                if (this.bMultiLine) {
                    divFontSize = parseInt(12 * ConfigInfo.PointToPx * scaleValue + 0.5);
                }
                else {
                    if (this.formWidget.curPageObj.rotate == 1 || this.formWidget.curPageObj.rotate == 3) {
                        divFontSize = parseInt(this.formWidget.rect.width * 0.7 * ConfigInfo.PointToPx * scaleValue + 0.5);
                    }
                    else {
                        divFontSize = parseInt(this.formWidget.rect.height * 0.7 * ConfigInfo.PointToPx * scaleValue + 0.5);
                    }
                }
            }

            SetStyleLTWH($("#" + this.formWidget.strBgID + "_div"), divBgLeft, divBgTop, divBgWidth, divBgHeight);
            if (this.bMultiLine) {
                var obj = $("#" + this.GetControlID());
                obj.css("max-width", divWidth + "px").css("max-height", divHeight + "px").css("font-size", divFontSize + "px");
                SetStyleLTWH(obj, divLeft, divTop, divWidth, divHeight);
            }
            else {
                var obj = $("#" + this.GetControlID());
                obj.css("line-height", divHeight + "px").css("font-size", divFontSize + "px");
                SetStyleLTWH(obj, divLeft, divTop, divWidth, divHeight);
            }
            SetStyleLTWH($("#" + this.formWidget.strFgID), divLeft, divTop, divWidth, divHeight);

            var imgLeft = 0 - parseInt(this.imgPos * scaleValue + 0.5);
            var imgWidth = parseInt(this.formWidget.curPageObj.allImgWidth * scaleValue + 0.5);
            var imgHeight = parseInt(this.formWidget.curPageObj.allImgHeight * scaleValue + 0.5);
            SetStyleLTWH($("#" + this.formWidget.strBgID), imgLeft, 0, imgWidth, imgHeight);
        };

        this.ChangeHighlight = function (bHighlight) {
            if (!this.formWidget.bReadOnly) {
                $("#" + this.formWidget.strFgID).css("display", (bHighlight ? "" : "none"));
            }

        };

        this.ResetData = function () {
            if (typeof (FXREADER.g_formValue.GetItemValue(this.formWidget.name)) == "undefined") {
                FXREADER.g_formValue.SetItemValue(this.formWidget.name, this.value);
            }
            this.bUnbind = true;
            var obj = $("#" + this.GetControlID());
            if (this.bMultiLine) {
                obj.val(this.value);
            }
            else {
                obj.attr("value", this.value);
            }
        };

        this.Update = function () {
            var curItemID = arguments[0] ? arguments[0] : "";
            if (curItemID == this.GetControlID()) {
                return;
            }

            var obj = $("#" + this.GetControlID());

            if (!this.formWidget.bReadOnly || this.bUnbind) {
                var value = FXREADER.g_formValue.GetItemValue(this.formWidget.name);
                if (typeof (value) == "undefined") {
                    value = "";
                }
                if (this.bMultiLine) {
                    obj.val(value);
                } else {
                    obj.attr("value", value);
                }
            }

            obj.attr("noupdate", "true").trigger("blur").trigger("C");
            if (this.formWidget.bReadOnly && this.bUnbind) {
                this.bUnbind = false;
                setTimeout(function () {
                    obj.unbind();
                    if (this.bMultiLine) {
                        $('#' + this.GetControlID()).bind('focus', { id: this.GetControlID(), fgid: this.formWidget.strFgID, bReadOnly: this.formWidget.bReadOnly, bSpellCheck: this.bSpellCheck }, TextareaFocus);
                        $('#' + this.GetControlID()).bind('blur', { id: this.GetControlID(), fgid: this.formWidget.strFgID, bReadOnly: this.formWidget.bReadOnly }, TextareaBlur);
                    }
                }, 1000);
            }
        };
    }
    //List
    function Option() {
        this.strID = "";
        this.bSelected = false;
        this.realValue = "";
        this.text = "";
    }

    function FormWidget_List() {
        this.formWidget = new FormWidget();
        this.value = "";
        this.bMultiple = false;
        this.imgPos = 0;
        this.optios = new Array();

        this.Parser = function (id, node, curPageObj) {
            this.formWidget.Parse(id, node, curPageObj);
            if (node) {
                var self = this;
                node.children("Options").each(function () {
                    var index = 0;
                    $(this).children("Option").each(function () {
                        var option = new Option();
                        option.strID = id + "_" + index.toString();
                        option.text = XMLStrToString($(this).text());
                        option.realValue = GetNodeString($(this), "realValue");
                        if (option.realValue == "") {
                            option.realValue = option.text;
                        }
                        option.bSelected = parseInt(GetNodeFloat($(this), "Selected")) > 0 ? true : false;
                        self.optios[index] = option;
                        index++;

                        if (option.bSelected) {
                            if (self.value != "") {
                                self.value += ";";
                            }
                            self.value += option.realValue;
                        }
                    });
                });

                node.children("Flags").each(function () {
                    $(this).children("MultiSelect").each(function () {
                        self.bMultiple = trim($(this).text()) == "1" ? true : false;
                    });
                });

                node.children("Ap").each(function () {
                    $(this).children("N").each(function () {
                        self.imgPos = GetNodeFloat($(this), "Path");
                    });
                });

                if (typeof (FXREADER.g_formValue.GetItemValue(this.formWidget.name)) == "undefined") {
                    FXREADER.g_formValue.SetItemValue(this.formWidget.name, this.value);
                }
            }
        };

        this.GetControlID = function () {
            return this.formWidget.GetControlID();
        };
        this.GetHtmlCode = function (bHighlight) {
            var divBgLeft = parseInt(this.formWidget.rect.left * ConfigInfo.PointToPx + 0.5);
            var divBgTop = parseInt(this.formWidget.rect.top * ConfigInfo.PointToPx + 0.5);
            var divBgWidth = parseInt(this.formWidget.rect.width * ConfigInfo.PointToPx + 0.5);
            var divBgHeight = parseInt(this.formWidget.rect.height * ConfigInfo.PointToPx + 0.5);
            var divBorderWidth = parseInt(this.formWidget.borderWidth * ConfigInfo.PointToPx + 0.5);
            var divFontSize = 0;
            if (this.formWidget.fontSize != -1) {
                divFontSize = parseInt(this.formWidget.fontSize * ConfigInfo.PointToPx + 0.5);
            }
            else {
                divFontSize = parseInt(12 * ConfigInfo.PointToPx + 0.5);
            }
            var strMultiple = this.bMultiple ? "true" : "false";
            var style_bg = String.Format(strFormatArr.styleLTWH + "position:absolute;padding:0;", 0 - this.imgPos, 0, this.formWidget.curPageObj.allImgWidth, this.formWidget.curPageObj.allImgHeight);
            var style_bgdiv = String.Format(strFormatArr.styleLTWH + "position:absolute;background-image:none;overflow:hidden;", divBgLeft, divBgTop, divBgWidth, divBgHeight);
            var strCode = String.Format("<div name='{0}'><div id='{1}' style='{2}'>",
                            this.formWidget.name, this.formWidget.strBgID + "_div", style_bgdiv);
            strCode += String.Format("<img class='fwr_form_widget' src='{0}' id='{1}' style='{2}'/>",
                            this.formWidget.curPageObj.m_imgUrl, this.formWidget.strBgID, style_bg);
            strCode += "</div>";

            var divLeft = divBgLeft + divBorderWidth;
            var divTop = divBgTop + divBorderWidth;
            var divWidth = divBgWidth - 2 * divBorderWidth;
            var divHeight = divBgHeight - 2 * divBorderWidth;

            var style = String.Format(strFormatArr.styleLTWH + "position:absolute;background-image:url(about:blank);background-color:transparent;overflow:auto;-moz-user-select:none;",
                        divLeft, divTop, divWidth, divHeight);
            strCode += String.Format("<div class='fwr_form_widget' id='{0}' name='{1}' style='{2}' multiple='{3}' tabindex=1>", this.GetControlID(), this.formWidget.name, style, strMultiple);

            for (var index = 0; index < this.optios.length; index++) {
                var tmp = this.optios[index];
                if (tmp) {
                    strCode += String.Format("<div id='{0}' tabindex=2 style='overflow: hidden; display: block;width:100%;font-size:{1}px;cursor:default;' class='{2} fwr_form_widget' selected='{3}' realValue='{4}'>{5}</div>",
                                tmp.strID, divFontSize, tmp.bSelected ? "fwr_form_listitem_selected" : "", tmp.bSelected ? "1" : "0", tmp.realValue, tmp.text);
                }
            }

            strCode += "</div>";
            style = String.Format(strFormatArr.styleLTWH, divLeft, divTop, divWidth, divHeight);
            style += "cursor:default;";
            if (!bHighlight || this.formWidget.bReadOnly) {
                style += "display:none";
            }
            strCode += String.Format("<div id='{0}' class='{1} fwr_form_widget' style='{2}'></div></div>", this.formWidget.strFgID, this.formWidget.bRequired ? "fwr_form_require_field_highlight" : "fwr_form_field_highlight", style);
            return strCode;
        };

        this.GetReadyBindCode = function () {
            if (!this.formWidget.bReadOnly) {
                var controlid = this.GetControlID();
                var obj = $('#' + controlid);
                for (var i = 0; i < this.optios.length; i++) {
                    var tmp = this.optios[i];
                    if (tmp) {
                        var itemObj = $('#' + tmp.strID);
                        itemObj.bind('click', { id: tmp.strID, listdivid: controlid }, ListItemClick);
                        itemObj.bind('keydown', { id: tmp.strID, listdivid: controlid }, ListItemKeydown);
                        itemObj.bind('focus', { id: controlid, fgid: this.formWidget.strFgID, bgid: this.formWidget.strBgID }, ListFocus);
                        itemObj.bind('blur', { id: controlid, fgid: this.formWidget.strFgID, bgid: this.formWidget.strBgID }, ListBlur);
                    }
                }
                //取消文本选择
                obj.bind('selectstart', function () { return false; }).trigger('selectstart');
                obj.bind('keydown', { id: controlid }, ListKeydown);
                obj.bind('focus', { id: controlid, fgid: this.formWidget.strFgID, bgid: this.formWidget.strBgID }, ListFocus);
                obj.bind('blur', { id: controlid, fgid: this.formWidget.strFgID, bgid: this.formWidget.strBgID }, ListBlur);
                $('#' + this.formWidget.strFgID).bind('click', { id: controlid, fgid: this.formWidget.strFgID, optiosCount: this.optios.length }, ListboxFgClick);
            }
        };

        this.ChangeSize = function (scaleValue) {
            var divBgLeft = parseInt(this.formWidget.rect.left * ConfigInfo.PointToPx * scaleValue + 0.5);
            var divBgTop = parseInt(this.formWidget.rect.top * ConfigInfo.PointToPx * scaleValue + 0.5);
            var divBgWidth = parseInt(this.formWidget.rect.width * ConfigInfo.PointToPx * scaleValue + 0.5);
            var divBgHeight = parseInt(this.formWidget.rect.height * ConfigInfo.PointToPx * scaleValue + 0.5);
            var divBorderWidth = parseInt(this.formWidget.borderWidth * ConfigInfo.PointToPx * scaleValue + 0.5);
            var divLeft = divBgLeft + divBorderWidth;
            var divTop = divBgTop + divBorderWidth;
            var divWidth = divBgWidth - 2 * divBorderWidth;
            var divHeight = divBgHeight - 2 * divBorderWidth;
            var divFontSize = 0;
            if (this.formWidget.fontSize != -1) {
                divFontSize = parseInt(this.formWidget.fontSize * ConfigInfo.PointToPx * scaleValue + 0.5);
            }
            else {
                divFontSize = parseInt(12 * ConfigInfo.PointToPx * scaleValue + 0.5);
            }

            SetStyleLTWH($("#" + this.formWidget.strBgID + "_div"), divBgLeft, divBgTop, divBgWidth, divBgHeight);

            var obj = $("#" + this.GetControlID());
            SetStyleLTWH(obj, divLeft, divTop, divWidth, divHeight);
            for (var index = 0; index < this.optios.length; index++) {
                var tmp = this.optios[index];
                if (tmp) {
                    obj = $("#" + tmp.strID);
                    obj.css("font-size", divFontSize + "px");
                }
            }

            SetStyleLTWH($("#" + this.formWidget.strFgID), divLeft, divTop, divWidth, divHeight);

            var imgLeft = 0 - parseInt(this.imgPos * scaleValue + 0.5);
            var imgWidth = parseInt(this.formWidget.curPageObj.allImgWidth * scaleValue + 0.5);
            var imgHeight = parseInt(this.formWidget.curPageObj.allImgHeight * scaleValue + 0.5);
            SetStyleLTWH($("#" + this.formWidget.strBgID), imgLeft, 0, imgWidth, imgHeight);
        };

        this.ChangeHighlight = function (bHighlight) {
            if (!this.formWidget.bReadOnly) {
                $("#" + this.formWidget.strFgID).css("display", (bHighlight ? "" : "none"));
            }

        };

        this.ResetData = function () {
            if (typeof (FXREADER.g_formValue.GetItemValue(this.formWidget.name)) == "undefined") {
                FXREADER.g_formValue.SetItemValue(this.formWidget.name, this.value);
            }

            for (var index = 0; index < this.optios.length; index++) {
                var tmp = this.optios[index];
                if (tmp) {
                    SelectComboItem($("#" + tmp.strID), tmp.bSelected);
                }
            }
        };

        this.Update = function () {
            var valueArr = null;
            var fieldValue = FXREADER.g_formValue.GetItemValue(this.formWidget.name);
            if (fieldValue && fieldValue != "") {
                valueArr = fieldValue.split(';');
            }

            for (var index = 0; index < this.optios.length; index++) {
                var tmp = this.optios[index];
                if (tmp) {
                    var bSelected = false;
                    for (i in valueArr) {
                        if (trim(valueArr[i]) == tmp.realValue) {
                            bSelected = true;
                            break;
                        }
                    }
                    SelectComboItem($("#" + tmp.strID), bSelected);
                }
            }
        };
    }
    //Combo
    function FormWidget_Combo() {
        this.formWidget = new FormWidget();
        this.listDivID = "";
        this.imgPos = 0;
        this.bEdit = false;
        this.optios = new Array();
        this.selectValue = "";
        this.selectText = "";
        this.value = "";
        this.inputID = "";

        this.Parser = function (id, node, curPageObj) {
            this.formWidget.Parse(id, node, curPageObj);
            this.listDivID = id + "_list";
            this.inputID = id + "_input";
            if (node) {
                var self = this;
                node.children("Options").each(function () {
                    var index = 0;
                    $(this).children("Option").each(function () {
                        var option = new Option();
                        option.strID = self.listDivID + "_" + index.toString();
                        option.text = XMLStrToString($(this).text());
                        option.realValue = GetNodeString($(this), "realValue");
                        if (option.realValue == "") {
                            option.realValue = option.text;
                        }
                        option.bSelected = parseInt(GetNodeFloat($(this), "Selected")) > 0 ? true : false;
                        self.optios[index] = option;
                        index++;

                        if (option.bSelected) {
                            self.selectValue = option.realValue;
                            self.selectText = option.text;
                        }
                    });
                });

                node.children("Value").each(function () {
                    self.value = trim($(this).text());
                });

                node.children("General").each(function () {
                    $(this).children("Edit").each(function () {
                        self.bEdit = trim($(this).text()) == "1" ? true : false;
                    });
                });

                node.children("Ap").each(function () {
                    $(this).children("N").each(function () {
                        self.imgPos = GetNodeFloat($(this), "Path");
                    });
                });

                if (typeof (FXREADER.g_formValue.GetItemValue(this.formWidget.name)) == "undefined") {
                    FXREADER.g_formValue.SetItemValue(this.formWidget.name, this.selectValue ? this.selectValue : this.value);
                }
            }
        };

        this.GetControlID = function () {
            return this.formWidget.GetControlID();
        };
        this.GetHtmlCode = function (bHighlight) {
            var divBgLeft = parseInt(this.formWidget.rect.left * ConfigInfo.PointToPx + 0.5);
            var divBgTop = parseInt(this.formWidget.rect.top * ConfigInfo.PointToPx + 0.5);
            var divBgWidth = parseInt(this.formWidget.rect.width * ConfigInfo.PointToPx + 0.5);
            var divBgHeight = parseInt(this.formWidget.rect.height * ConfigInfo.PointToPx + 0.5);
            var divBorderWidth = parseInt(this.formWidget.borderWidth * ConfigInfo.PointToPx + 0.5);
            var divLeft = divBgLeft + divBorderWidth;
            var divTop = divBgTop + divBorderWidth;
            var divWidth = divBgWidth - 2 * divBorderWidth;
            var divHeight = divBgHeight - 2 * divBorderWidth;
            var divFontSize = 0;
            var listFontSize = 0;
            if (this.formWidget.fontSize != -1) {
                divFontSize = parseInt(this.formWidget.fontSize * ConfigInfo.PointToPx + 0.5);
                listFontSize = divFontSize;
            }
            else {
                if (this.formWidget.curPageObj.rotate == 1 || this.formWidget.curPageObj.rotate == 3) {
                    divFontSize = parseInt(this.formWidget.rect.width * 0.7 * ConfigInfo.PointToPx + 0.5);
                }
                else {
                    divFontSize = parseInt(this.formWidget.rect.height * 0.7 * ConfigInfo.PointToPx + 0.5);
                }
                listFontSize = parseInt(12 * ConfigInfo.PointToPx + 0.5);
            }
            var listDivTop = divBgTop + divBgHeight;
            var style_bg = String.Format(strFormatArr.styleLTWH + "position:absolute;padding:0;", 0 - this.imgPos, 0, this.formWidget.curPageObj.allImgWidth, this.formWidget.curPageObj.allImgHeight);
            var style_bgdiv = String.Format(strFormatArr.styleLTWH + "position:absolute;background-image:none;overflow:hidden;", divBgLeft, divBgTop, divBgWidth, divBgHeight);
            var strCode = String.Format("<div name='{0}'><div id='{1}' style='{2}'>", this.formWidget.name, this.formWidget.strBgID + "_div", style_bgdiv);
            strCode += String.Format("<img class='fwr_form_widget' src='{0}' id='{1}' style='{2}'/>",
                            this.formWidget.curPageObj.m_imgUrl, this.formWidget.strBgID, style_bg);
            strCode += "</div>";

            var style = String.Format(strFormatArr.styleLTWH + "line-height:{3}px;position:absolute;font-size:{4}px;text-align:center;padding:0;background-image:url(about:blank);",
                        divLeft, divTop, divWidth, divHeight, divFontSize);
            strCode += String.Format("<div class='fwr_form_widget' id='{0}' name='{1}' style='{2}' tabindex=1></div>", this.GetControlID(), this.formWidget.name, style);

            var tmpdivLeft = divLeft;
            var tmpdivTop = divTop;
            var tmpdivWidth = divWidth;
            var tmpdivHeight = divHeight;
            var rightWidth = parseInt(16 * ConfigInfo.PointToPx + 0.5);
            switch (this.formWidget.curPageObj.rotate) {
                case 1:
                    //90
                    {
                        tmpdivHeight = tmpdivHeight - rightWidth;
                    }
                    break;
                case 2:
                    //180
                    {
                        tmpdivWidth = tmpdivWidth - rightWidth;
                        tmpdivLeft = tmpdivLeft + rightWidth;
                    }
                    break;
                case 3:
                    //270
                    {
                        tmpdivHeight = tmpdivHeight - rightWidth;
                        tmpdivTop = tmpdivTop + rightWidth;
                    }
                    break;
                default:
                    //0
                    {
                        tmpdivWidth = tmpdivWidth - rightWidth;
                    }
            }

            style = String.Format(strFormatArr.styleLTWH + "line-height:{3}px;position:absolute;font-size:{4}px;background-image:url(about:blank);background-color:transparent;padding:0;border:0;",
                        tmpdivLeft, tmpdivTop, tmpdivWidth, tmpdivHeight, divFontSize);
            strCode += String.Format("<input class='fwr_form_widget' type='text' id='{0}' style='{1}' value='{2}' oldValue='{2}' realValue='{3}' {4}/>",
                            this.inputID, style, this.selectValue ? this.selectText : this.value, this.selectValue ? this.selectValue : this.value, (this.formWidget.bReadOnly || !this.bEdit) ? "readonly='readonly'" : "");

            style = String.Format("left:{0}px;top:{1}px;width:{2}px;position: absolute;background-color:#ffffff;border: 1px solid #6ea3c4;display:none;overflow:auto;",
                        divBgLeft, listDivTop, divBgWidth);
            strCode += String.Format("<div id='{0}' style='{1}' class='fwr_form_widget_comboxlist' tabindex=2>", this.listDivID, style);
            for (var index = 0; index <= this.optios.length; index++) {
                var tmp = this.optios[index];
                if (tmp) {
                    strCode += String.Format("<div id='{0}' style='overflow: hidden;display: block;width:100%;font-size:{1}px;' tabindex=3 class='fwr_form_combobox_item {2}' selected='{3}'  realValue='{4}'>{5}</div>",
                                    tmp.strID, listFontSize, tmp.bSelected ? "fwr_form_listitem_selected" : "", tmp.bSelected ? "1" : "0", tmp.realValue, tmp.text);
                }
            }
            strCode += "</div>";

            style = String.Format(strFormatArr.styleLTWH, divLeft, divTop, divWidth, divHeight);
            style += "cursor:default;";
            if (!bHighlight || this.formWidget.bReadOnly) {
                style += "display:none";
            }

            strCode += String.Format("<div id='{0}' class='{1} fwr_form_widget' style='{2}'></div></div>", this.formWidget.strFgID, this.formWidget.bRequired ? "fwr_form_require_field_highlight" : "fwr_form_field_highlight", style);
            return strCode;
        };

        this.GetReadyBindCode = function () {
            if (!this.formWidget.bReadOnly) {
                var controlid = this.GetControlID();
                $('#' + controlid).bind('focus', { inputid: this.inputID }, ComboButFocusOrFgFocus);
                $('#' + controlid).bind('click', { inputid: this.inputID }, ComboButFocusOrFgClick);
                $("#" + this.inputID).bind('focus', { id: controlid, listdivid: this.listDivID, fgid: this.formWidget.strFgID, inputid: this.inputID, bgid: this.formWidget.strBgID }, ComboButIputFocus);
                $("#" + this.inputID).bind('click', { listdivid: this.listDivID, fgid: this.formWidget.strFgID }, ComboButIputClick);
                $("#" + this.inputID).bind('blur', { id: controlid, listdivid: this.listDivID, fgid: this.formWidget.strFgID, inputid: this.inputID, bgid: this.formWidget.strBgID }, ComboButIputBlur);
                $("#" + this.listDivID).bind('blur', { id: controlid, listdivid: this.listDivID, fgid: this.formWidget.strFgID, inputid: this.inputID, bgid: this.formWidget.strBgID }, ComboButIputBlur);
                for (var i = 0; i < this.optios.length; i++) {
                    var tmp = this.optios[i];
                    if (tmp) {
                        $('#' + tmp.strID).bind('click', { id: tmp.strID, combodivid: controlid }, ComboListItemClick);
                        $("#" + tmp.strID).bind('blur', { id: controlid, listdivid: this.listDivID, fgid: this.formWidget.strFgID, inputid: this.inputID, bgid: this.formWidget.strBgID }, ComboButIputBlur);
                    }
                }
                $('#' + this.formWidget.strFgID).bind('click', { inputid: this.inputID }, ComboButFocusOrFgClick);
            }
        };

        this.ChangeSize = function (scaleValue) {
            var divBgLeft = parseInt(this.formWidget.rect.left * ConfigInfo.PointToPx * scaleValue + 0.5);
            var divBgTop = parseInt(this.formWidget.rect.top * ConfigInfo.PointToPx * scaleValue + 0.5);
            var divBgWidth = parseInt(this.formWidget.rect.width * ConfigInfo.PointToPx * scaleValue + 0.5);
            var divBgHeight = parseInt(this.formWidget.rect.height * ConfigInfo.PointToPx * scaleValue + 0.5);
            var divBorderWidth = parseInt(this.formWidget.borderWidth * ConfigInfo.PointToPx * scaleValue + 0.5);
            var divLeft = divBgLeft + divBorderWidth;
            var divTop = divBgTop + divBorderWidth;
            var divWidth = divBgWidth - 2 * divBorderWidth;
            var divHeight = divBgHeight - 2 * divBorderWidth;
            var listDivTop = divBgTop + divBgHeight;
            var divFontSize = 0;
            var listFontSize = 0;
            if (this.formWidget.fontSize != -1) {
                divFontSize = parseInt(this.formWidget.fontSize * ConfigInfo.PointToPx * scaleValue + 0.5);
                listFontSize = divFontSize;
            }
            else {
                if (this.formWidget.curPageObj.rotate == 1 || this.formWidget.curPageObj.rotate == 3) {
                    divFontSize = parseInt(this.formWidget.rect.width * 0.7 * ConfigInfo.PointToPx * scaleValue + 0.5);
                }
                else {
                    divFontSize = parseInt(this.formWidget.rect.height * 0.7 * ConfigInfo.PointToPx * scaleValue + 0.5);
                }
                listFontSize = parseInt(12 * ConfigInfo.PointToPx * scaleValue + 0.5);
            }

            SetStyleLTWH($("#" + this.formWidget.strBgID + "_div"), divBgLeft, divBgTop, divBgWidth, divBgHeight);

            var obj = $("#" + this.GetControlID());
            obj.css("line-height", divHeight + "px").css("font-size", divFontSize + "px");
            SetStyleLTWH(obj, divLeft, divTop, divWidth, divHeight);

            var tmpdivLeft = divLeft;
            var tmpdivTop = divTop;
            var tmpdivWidth = divWidth;
            var tmpdivHeight = divHeight;
            var rightWidth = parseInt(16 * ConfigInfo.PointToPx * scaleValue + 0.5);
            switch (this.formWidget.curPageObj.rotate) {
                case 1:
                    //90
                    {
                        tmpdivHeight = tmpdivHeight - rightWidth;
                    }
                    break;
                case 2:
                    //180
                    {
                        tmpdivWidth = tmpdivWidth - rightWidth;
                        tmpdivLeft = tmpdivLeft + rightWidth;
                    }
                    break;
                case 3:
                    //270
                    {
                        tmpdivHeight = tmpdivHeight - rightWidth;
                        tmpdivTop = tmpdivTop + rightWidth;
                    }
                    break;
                default:
                    //0
                    {
                        tmpdivWidth = tmpdivWidth - rightWidth;
                    }
            }
            obj = $("#" + this.inputID);
            obj.css("line-height", tmpdivHeight + "px").css("font-size", divFontSize + "px");
            SetStyleLTWH(obj, tmpdivLeft, tmpdivTop, tmpdivWidth, tmpdivHeight);

            obj = $("#" + this.listDivID);
            obj.css("left", divBgLeft + "px").css("top", listDivTop + "px").css("width", divBgWidth + "px");

            for (var index = 0; index <= this.optios.length; index++) {
                var tmp = this.optios[index];
                if (tmp) {
                    $("#" + tmp.strID).css("font-size", listFontSize + "px");
                }
            }

            SetStyleLTWH($("#" + this.formWidget.strFgID), divLeft, divTop, divWidth, divHeight);

            var imgLeft = 0 - parseInt(this.imgPos * scaleValue + 0.5);
            var imgWidth = parseInt(this.formWidget.curPageObj.allImgWidth * scaleValue + 0.5);
            var imgHeight = parseInt(this.formWidget.curPageObj.allImgHeight * scaleValue + 0.5);
            SetStyleLTWH($("#" + this.formWidget.strBgID), imgLeft, 0, imgWidth, imgHeight);
        };

        this.ChangeHighlight = function (bHighlight) {
            if (!this.formWidget.bReadOnly) {
                $("#" + this.formWidget.strFgID).css("display", (bHighlight ? "" : "none"));
            }

        };

        this.ResetData = function () {
            if (typeof (FXREADER.g_formValue.GetItemValue(this.formWidget.name)) == "undefined") {
                FXREADER.g_formValue.SetItemValue(this.formWidget.name, this.selectValue ? this.selectValue : this.value);
            }
            for (var index = 0; index <= this.optios.length; index++) {
                var tmp = this.optios[index];
                if (tmp) {
                    SelectComboItem($("#" + tmp.strID), tmp.bSelected);
                }
            }
        };

        this.Update = function () {
            var fieldValue = FXREADER.g_formValue.GetItemValue(this.formWidget.name);
            if (typeof (fieldValue) == "undefined") {
                fieldValue = "";
            }
            var inputObj = $("#" + this.inputID);
            inputObj.attr("realValue", fieldValue)
            inputObj.attr("oldValue", fieldValue)
            inputObj.val(fieldValue);

            for (var index = 0; index <= this.optios.length; index++) {
                var tmp = this.optios[index];
                if (tmp) {
                    var bSelected = tmp.realValue == fieldValue;
                    if (bSelected) {
                        inputObj.attr("oldValue", tmp.text)
                        inputObj.val(tmp.text);
                    }
                    SelectComboItem($("#" + tmp.strID), bSelected);
                }
            }
        };
    }

    function CreateWidget(id, node, curPageObj) {
        var widget = null;
        var type;

        if (node) {
            type = parseInt(GetNodeFloat(node, "Type"));

            if (type == Type.PushButton) {
                widget = new FormWidget_PushBtn();
                widget.Parser(id, node, curPageObj);
            } else if (type == Type.RadioButton) {
                widget = new FormWidget_Radio();
                widget.Parser(id, node, curPageObj);
            } else if (type == Type.CheckBox) {
                widget = new FormWidget_Check();
                widget.Parser(id, node, curPageObj);
            } else if (type == Type.Text || type == Type.RichText) {
                widget = new FormWidget_Text();
                widget.Parser(id, node, curPageObj);
            } else if (type == Type.ListBox) {
                widget = new FormWidget_List();
                widget.Parser(id, node, curPageObj);
            } else if (type == Type.ComboBox) {
                widget = new FormWidget_Combo();
                widget.Parser(id, node, curPageObj);
            }
        }
        return widget;
    }
    //FormPage
    function FormPage() {
        this.scale = 1;
        this.strID = "";
        this.strBgID = "";
        this.pdfRect = new FloatRect();
        this.rotate = 0;
        this.pageWidth = 0;
        this.pageHeight = 0;
        this.imgPos = 0;
        this.allImgWidth = 0;
        this.allImgHeight = 0;
        this.m_imgUrl = "";
        this.formWidgets = new Array();
        this.m_iPageNum = 0;
        this.m_formFileNo = "";
        this.m_bLastPage = false;

        this.divWidth = 0;
        this.divHeight = 0;

        this.ParserLastPage = function (id, pageNo, formFileNo, divWidth,
				divHeight) {
            this.m_bLastPage = true;
            this.strID = id;
            this.m_iPageNum = pageNo;
            this.m_formFileNo = formFileNo;
            this.divWidth = divWidth;
            this.divHeight = divHeight;
        };

        this.Parser = function (id, pageNo, formFileNo, node) {
            this.strID = id;
            this.strBgID = id + "_bg";
            this.m_iPageNum = pageNo;
            this.m_formFileNo = formFileNo;
            this.m_imgUrl = FXREADER.Config.Url.GetFormWidgetBGImg + "?page=" + this.m_iPageNum + "&" + this.m_formFileNo;
            if (node) {
                var self = this;
                node.each(function () {
                    $(this).children("State").each(function () {
                        self.rotate = parseInt(GetNodeFloat($(this), "Rotate"));
                        self.pdfRect.SetValue(GetNodeFloat($(this), "l"), GetNodeFloat($(this), "b"), GetNodeFloat($(this), "Width"), GetNodeFloat($(this), "Height"));
                        $(this).children("Ap").each(function () {
                            self.imgPos = GetNodeFloat($(this), "Path");
                        });
                    });
                    $(this).children("ImgInfo").each(function () {
                        self.allImgWidth = GetNodeFloat($(this), "Width");
                        self.allImgHeight = GetNodeFloat($(this), "Height");
                    });
                });

                switch (this.rotate) {
                    case 1:
                    case 3:
                        //90 or 270
                        {
                            this.pageHeight = this.pdfRect.width;
                            this.pageWidth = this.pdfRect.height;
                        }
                        break;
                    case 2:
                    default:
                        //0 or 180
                        {
                            this.pageHeight = this.pdfRect.height;
                            this.pageWidth = this.pdfRect.width;
                        }
                }

                var curFormPageObj = this;
                node.each(function () {
                    $(this).children("Form").each(function () {
                        var index = 0;
                        $(this).children("Widget").each(function () {
                            self.formWidgets[index] = CreateWidget(id + "_" + index.toString(), $(this), curFormPageObj);
                            index++;
                        });

                    });
                });
            }
        };

        this.GetHtmlCode = function (bHighlight) {
            if (this.m_bLastPage) {
                var style = String.Format(strFormatArr.styleLTWH + "position:absolute;background-color:transparent;", 0, 0, this.divWidth, this.divHeight);
                var divCode = "<div class='border' id='{0}' style='{1}'>" +
                        "<button id='btnreset' style='margin:20px 50px;' class='fwr_button blue fwr_dialog_btn_cancel fr' name='btnreset' type='button'>{2}</button>" +
                        "<button id='btnsubmit' style='margin:20px 0px;' class='fwr_button orange fwr_dialog_btn_ok fr' name='btnsubmit' type='button'>{3}</button></div>";
                return String.Format(divCode, this.strID, style, strArr.resetText, strArr.submitText);
            }

            this.divWidth = this.pageWidth * ConfigInfo.PointToPx;
            this.divHeight = this.pageHeight * ConfigInfo.PointToPx;
            var style = String.Format(strFormatArr.styleLTWH + "position:absolute;", 0, 0, parseInt(this.divWidth + 0.5), parseInt(this.divHeight + 0.5));

            var strCode = String.Format("<div id='{0}' style='background-color:transparent;{1}'>", this.strID, style);
            for (var i = 0; i < this.formWidgets.length; i++) {
                if (this.formWidgets[i]) {
                    strCode += this.formWidgets[i].GetHtmlCode(bHighlight);
                }
            }
            strCode += "</div>";
            return strCode;
        };

        this.GetRegisterActionCode = function () {
            for (var i = 0; i < this.formWidgets.length; i++) {
                if (this.formWidgets[i]) {
                    this.formWidgets[i].formWidget.GetRegisterActionCode();
                }
            }
        };

        this.GetReadyBindCode = function () {
            if (this.m_bLastPage) {
                $("#btnreset").bind("click", function () {
                    resetForm();
                    return false;
                });

                $("#btnsubmit").bind("click", function () {
                    submitForm();
                    return false;
                });
            }

            for (var i = 0; i < this.formWidgets.length; i++) {
                if (this.formWidgets[i]) {
                    this.formWidgets[i].GetReadyBindCode();
                }
            }
        };

        this.ChangeSize = function (scaleValue) {
            if (scaleValue == this.scale) {
                return;
            }

            this.scale = scaleValue;
            var width = parseInt(this.divWidth * scaleValue + 0.5);
            var height = parseInt(this.divHeight * scaleValue + 0.5);
            SetStyleLTWH($("#" + this.strID), 0, 0, width, height);
            if (this.m_bLastPage) {
                var margin20 = parseInt(20 * scaleValue + 0.5);
                var margin50 = parseInt(50 * scaleValue + 0.5);
                var fontSize = parseInt(11 * scaleValue + 0.5);
                var butHeight = parseInt(25 * scaleValue + 0.5);
                var butWidth = parseInt(80 * scaleValue + 0.5);
                $("#btnreset").css("margin", margin20 + "px " + margin50 + "px").css("font-size", fontSize + "px").css("height", butHeight + "px").css("width", butWidth + "px").css("min-width", butWidth + "px");
                $("#btnsubmit").css("margin", margin20 + "px 0px").css("font-size", fontSize + "px").css("height", butHeight + "px").css("width", butWidth + "px").css("min-width", butWidth + "px");
            } else {
                for (var i = 0; i < this.formWidgets.length; i++) {
                    if (this.formWidgets[i]) {
                        this.formWidgets[i].ChangeSize(scaleValue);
                    }
                }
            }
        };

        this.ShowPage = function () {
            $("#" + this.strID).show();
            for (var i = 0; i < this.formWidgets.length; i++) {
                if (this.formWidgets[i]) {
                    this.formWidgets[i].Update();
                }
            }
        };

        this.HidePage = function () {
            $("#" + this.strID).hide();
        };

        this.ChangeHighlight = function (bHighlight) {
            for (var i = 0; i < this.formWidgets.length; i++) {
                if (this.formWidgets[i]) {
                    this.formWidgets[i].ChangeHighlight(bHighlight);
                }
            }
        };

        this.ResetData = function () {
            for (var i = 0; i < this.formWidgets.length; i++) {
                if (this.formWidgets[i]) {
                    this.formWidgets[i].ResetData();
                }
            }
            for (var i = 0; i < this.formWidgets.length; i++) {
                if (this.formWidgets[i]) {
                    this.formWidgets[i].Update();
                }
            }
        };

        this.Update = function (name) {
            for (var i = 0; i < this.formWidgets.length; i++) {
                if (this.formWidgets[i] && this.formWidgets[i].formWidget.name == name) {
                    this.formWidgets[i].Update(arguments[1]);
                }
            }
        };

        this.GetRadioGroupSelectedItemID = function (name) {
            var id = "";
            for (var i = 0; i < this.formWidgets.length; i++) {
                if (this.formWidgets[i] && this.formWidgets[i].formWidget.name == name) {
                    var tmpid = this.formWidgets[i].GetControlID();
                    if ($("#" + tmpid).attr("checked") == "1") {
                        id = tmpid;
                        break;
                    }
                }
            }
            return id;
        };

        this.CheckRequiredWidget = function () {
            for (var i = 0; i < this.formWidgets.length; i++) {
                if (this.formWidgets[i] && this.formWidgets[i].formWidget.bRequired && !FXREADER.g_formValue.GetItemValue(this.formWidgets[i].formWidget.name)) {
                    return false;
                }
            }
            return true;
        };

        this.Transform = function (pdf_l, pdf_b, pdf_w, pdf_h) {
            var retFloatRect = new FloatRect();

            switch (this.rotate) {
                //90                      
                case 1:
                    {
                        retFloatRect.top = pdf_l - this.pdfRect.left;
                        retFloatRect.left = pdf_b - this.pdfRect.top;
                        retFloatRect.width = pdf_h;
                        retFloatRect.height = pdf_w;
                    }
                    break;
                //180                      
                case 2:
                    {
                        retFloatRect.top = pdf_b - this.pdfRect.top;
                        retFloatRect.left = this.pdfRect.width - pdf_l - this.pdfRect.left - pdf_w;
                        retFloatRect.width = pdf_w;
                        retFloatRect.height = pdf_h;
                    }
                    break;
                case 3:
                    //270
                    {
                        retFloatRect.top = this.pdfRect.width - (pdf_l - this.pdfRect.left) - pdf_w;
                        retFloatRect.left = this.pdfRect.height - (pdf_b - this.pdfRect.top) - pdf_h;
                        retFloatRect.width = pdf_h;
                        retFloatRect.height = pdf_w;
                    }
                    break;
                default:
                    //0
                    {
                        retFloatRect.top = this.pdfRect.height - (pdf_b - this.pdfRect.top) - pdf_h;
                        retFloatRect.left = pdf_l - this.pdfRect.left;
                        retFloatRect.width = pdf_w;
                        retFloatRect.height = pdf_h;
                    }
            }

            return retFloatRect;
        };
    }

    /////////////////////////////////////////////////////////////////////////////////解析及显示 End

    /////////////////////////////////////////////////////////////////////////////////保存表单域值 Start
    //Form Filed Value
    //获取默认值
    //var g_formValue = new FormValue();
    function FormValue() {
        this.items = new Array();
        this.itemsActionJScriptChange = new Array();

        this.ClearAll = function () {
            this.items = new Array();
            this.itemsActionJScriptChange = new Array();
        };

        this.GetItemValue = function (name) {
            return this.items[name];
        };

        this.SetItemValue = function (name, value) {
            if (this.itemsActionJScriptChange[name]) {
                this.itemsActionJScriptChange[name] = false;
            } else {
                this.items[name] = value;
            }
        };

        this.SetItemValue_ActionJScript = function (name, value) {
            this.itemsActionJScriptChange[name] = true;
            this.items[name] = value;
        };

        this.GetFormDataXML = function () {
            var dataStr = '<?xml version="1.0" encoding="UTF-8"?><fields xmlns:xfdf="http://ns.adobe.com/xfdf-transition/">';

            var index = 0;
            for (name in this.items) {
                if (typeof (this.items[name]) != "undefined") {
                    var tag = "FormField" + index.toString();
                    dataStr += String.Format('<{0} xfdf:original="{1}">{2}</{0}>', tag, name, StringToXMLStr(this.items[name].toString()));
                    if (this.items[name].toString() != "") {
                        index++;
                    }
                }
            }
            dataStr += '</fields>';
            return index == 0 ? "" : dataStr;
        };
    }
    /////////////////////////////////////////////////////////////////////////////////保存表单域值 End

    function Update(name) {
        var pages = FXREADER.g_pFormPlugin.m_Pages;
        for (key in pages) {
            if (pages[key] != null)
                pages[key].Update(name, arguments[1]);
        }
    }
    //PushButton
    var g_mouseLeftDown = false;
    var g_mouseOverArr = new Array();
    function PushButFgClick(event) {
        setTimeout(function () {
            $("#" + event.data.id).focus().trigger("mouseover");
        }, 0);
    }
    function PushButFocus(event) {
        if ($("#" + event.data.id).hasClass("fwr_form_widget")) {
            //将其z-index修改为form_widget_comboxlist
            $("#" + event.data.id).removeClass("fwr_form_widget").addClass("fwr_form_widget_comboxlist");

            if (FXREADER.g_pFormPlugin.m_bHighlight) {
                $("#" + event.data.fgid).css("display", "none");
            }
        }
    }
    function PushButBlur(event) {
        setTimeout(function () {
            if (!document.activeElement.id || trim(document.activeElement.id).toLowerCase() != trim(event.data.id).toLowerCase()) {
                //将其z-index修改为fwr_form_widget_comboxlist
                $("#" + event.data.id).removeClass("fwr_form_widget_comboxlist").addClass("fwr_form_widget");

                if (FXREADER.g_pFormPlugin.m_bHighlight) {
                    $("#" + event.data.fgid).css("display", "");
                }
            }
        }, 0);
    }
    function PushButMouseOut(event) {
        var key = trim(event.data.id).toLowerCase();
        //if(g_mouseOverArr[key] == true)
        //{
        if (!g_mouseLeftDown) {
            var curPageObj = FXREADER.g_pFormPlugin.m_Pages[event.data.curPageNum];
            var leftValue = 0 - parseInt(event.data.nImgPos * curPageObj.scale + 0.5);
            $("#" + event.data.id).css("left", leftValue + "px");
        }
        g_mouseOverArr[key] = false;
        //}
    }
    function PushButMouseOver(event) {
        var key = trim(event.data.id).toLowerCase();
        //if(g_mouseOverArr[key] != true)
        //{
        if (!g_mouseLeftDown) {
            var curPageObj = FXREADER.g_pFormPlugin.m_Pages[event.data.curPageNum];
            var leftValue = 0 - parseInt(event.data.rImgPos * curPageObj.scale + 0.5);
            $("#" + event.data.id).css("left", leftValue + "px");
        }
        g_mouseOverArr[key] = true;
        //}
    }

    function PushButMouseMove(event) {
        var key = trim(event.data.id).toLowerCase();
        //if(g_mouseOverArr[key] != true)
        //{
        if (!g_mouseLeftDown) {
            var curPageObj = FXREADER.g_pFormPlugin.m_Pages[event.data.curPageNum];
            var leftValue = 0 - parseInt(event.data.rImgPos * curPageObj.scale + 0.5);
            $("#" + event.data.id).css("left", leftValue + "px");
        }
        g_mouseOverArr[key] = true;
        //}
    }

    function isMouseLeftButDown(event) {
        //文档模式 IE9不支持:arguments.caller.length
        var checkIE9 = null;
        try { checkIE9 = arguments.caller.length; } catch (e) { }

        var bLeftBtn = false;
        if (navigator.userAgent.indexOf("MSIE") > 0 && checkIE9 != null) {
            //IE9之前文档模式左键按钮是1
            if (event.button == 1)
                bLeftBtn = true;
        }
        else {
            if (event.button == 0)
                bLeftBtn = true;
        }
        return bLeftBtn;
    }

    function PushButMouseDown(event) {
        var key = trim(event.data.id).toLowerCase();
        //if(g_mouseOverArr[key] == true)
        //{
        if (isMouseLeftButDown(event)) {
            var element = document.getElementById(event.data.id);
            var curPageObj = FXREADER.g_pFormPlugin.m_Pages[event.data.curPageNum];
            var leftValueN = 0 - parseInt(event.data.nImgPos * curPageObj.scale + 0.5);
            var leftValueR = 0 - parseInt(event.data.rImgPos * curPageObj.scale + 0.5);
            var leftValueD = 0 - parseInt(event.data.dImgPos * curPageObj.scale + 0.5);
            $("#" + event.data.id).css("left", leftValueD + "px");
            g_mouseLeftDown = true;

            if (event.preventDefault) {
                event.preventDefault();
            }

            if (window.captureEvents) {
                window.captureEvents(Event.MOUSEUP);
            } else if (element.setCapture) {
                element.setCapture();
            }

            var id = event.data.id;
            var d = document;
            d.onmouseup = function (e) {
                e = e || window.event;
                if (isMouseLeftButDown(e)) {
                    //取消捕获范围
                    if (window.releaseEvents) {
                        window.releaseEvents(Event.MOUSEUP);
                    } else if (element.releaseCapture) {
                        element.releaseCapture();
                    }

                    if (g_mouseOverArr[key] != true || navigator.userAgent.indexOf("MSIE") > 0 || navigator.userAgent.toLowerCase().indexOf("trident") > 0 ) {
                        $("#" + id).css("left", leftValueN + "px");
                    } else {
                        $("#" + id).css("left", leftValueR + "px");
                    }
                    g_mouseLeftDown = false;
                    //清除事件
                    d.onmouseup = null;
                }
            };
        }
        //}
    }
    ///end PushButton

    function CheckedObj(checkRaidoObj, bChecked) {
        var obj = $("#" + checkRaidoObj.GetControlID());
        var bCurChecked = (obj.attr("checked") == "1");
        var imgLeft = 0 - parseInt((bChecked ? checkRaidoObj.onImgPos : checkRaidoObj.offImgPos) * checkRaidoObj.formWidget.curPageObj.scale + 0.5);
        if (bChecked && !bCurChecked) {
            obj.attr("checked", "1").css("left", imgLeft + "px");
        }
        else if (!bChecked && bCurChecked) {
            obj.attr("checked", "0").css("left", imgLeft + "px");
        }
    }
    function CheckRaidoButFgClick(event) {
        setTimeout(function () {
            $("#" + event.data.id).focus().click();
        }, 0);
    }
    function CheckRaidoButFocus(event) {
        //将其z-index修改为form_widget_comboxlist
        $("#" + event.data.id).removeClass("fwr_form_widget").addClass("fwr_form_widget_comboxlist");

        if (FXREADER.g_pFormPlugin.m_bHighlight) {
            $("#" + event.data.fgid).css("display", "none");
        }
    }
    function CheckRaidoButBlur(event) {
        setTimeout(function () {
            if (!document.activeElement.id ||
                (trim(document.activeElement.id).toLowerCase() != trim(event.data.id).toLowerCase())) {
                //将其z-index修改为form_widget_comboxlist
                $("#" + event.data.id).removeClass("fwr_form_widget_comboxlist").addClass("fwr_form_widget");

                if (FXREADER.g_pFormPlugin.m_bHighlight) {
                    $("#" + event.data.fgid).css("display", "");
                }
            }
        }, 0);
    }

    //Check
    function CheckButClick(event) {
        var obj = $("#" + event.data.id);
        var value = "Off";
        if (obj.attr("checked") != "1") {
            value = obj.attr("value");
        }
        FXREADER.g_formValue.SetItemValue(obj.attr("name"), value);
        Update(obj.attr("name"));
    }
    //Raido
    function RaidoButClick(event) {
        var obj = $("#" + event.data.id);
        if (obj.attr("checked") != "1") {
            FXREADER.g_formValue.SetItemValue(obj.attr("name"), obj.attr("value"));
            Update(obj.attr("name"), obj.attr("id"));
        }
        else if (!event.data.bNoToggleToOff) {
            FXREADER.g_formValue.SetItemValue(obj.attr("name"), "Off");
            Update(obj.attr("name"), obj.attr("id"));
        }
    }
    //Text
    //传入要获取选择文本的input或者textarea对象ID
    function getSelectedText(objID) {
        var e = document.getElementById(objID);
        if (document.selection) {
            //IE下获取选择文本
            return document.selection.createRange().text;
        }
        else if (window.getSelection().toString()) {
            //firefox下获取选择文本
            return window.getSelection().toString();
        }
        else if (e.selectionStart != undefined && e.selectionEnd != undefined) {
            //firefox下获取input或textArea域的选择文本
            var start = e.selectionStart;
            var end = e.selectionEnd;
            return e.value.substring(start, end);
        }
    }

    function spellCeck(value, bTextarea, obj, spanObj) {
        //解决空格测不出长度问题;
        var str = value.replace(/ /g, '&nbsp;');
        var objWidth = obj.width();
        if (bTextarea) {
            var rowCount = parseInt(obj.height() / parseFloat(obj.css("font-size")));
            objWidth = objWidth * rowCount;
            while (rowCount > 1) {
                //占位,供计算
                str += "M";
                rowCount -= 1;
            }
        }
        spanObj.html(str);
        return spanObj.width() > objWidth;
    }

    function TextSpellCeck(event) {
        if (event.ctrlKey) {
            return;
        }
        var code;
        if (document.all) {
            //判断是否是IE浏览器
            code = window.event.keyCode;
        } else {
            code = arguments.callee.caller.arguments[0].which;
        }
        if (code == 8 || code == 46) {
            return true;
        }

        var character = String.fromCharCode(code);
        var obj = $("#" + event.data.id);
        var bUpperLimit = false;
        var selectedStr = getSelectedText(event.data.id);
        var str = "";
        if (selectedStr && selectedStr != "") {
            str = obj.val().replace(selectedStr, character);
        }
        else {
            str = obj.val() + character;
        }
        var spanCode = String.Format('<span id= "SpellCeckSpan" style= "visibility:hidden;border:0;padding:0;font-size:{0};"></span>', obj.css("font-size"));
        obj.after(spanCode);
        var tmpSpanObj = $("#SpellCeckSpan");
        bUpperLimit = spellCeck(str, event.data.bTextarea, obj, tmpSpanObj);
        tmpSpanObj.remove();

        //特殊字符正则表达式
        if (bUpperLimit) {
            if (document.all) {
                window.event.returnValue = false;
                return false;
            } else {
                arguments.callee.caller.arguments[0].preventDefault();
                return true;
            }
        }
    }

    function checkPasteTextWidth(id, bTextarea) {
        var obj = $("#" + id);
        var value = obj.val();

        var spanCode = String.Format('<span id= "SpellCeckSpan" style= "visibility:hidden;border:0;padding:0;font-size:{0};"></span>', obj.css("font-size"));
        obj.after(spanCode);
        var tmpSpanObj = $("#SpellCeckSpan");

        //while (true) {
        for (var ii = 0; ii < 1; ) {
            if (spellCeck(value, bTextarea, obj, tmpSpanObj)) {
                value = value.substr(0, value.length - 1);
            }
            else {
                break;
            }
        }
        tmpSpanObj.remove();
        obj.val(value);
    }

    function TextPaste(event) {
        var obj = $("#" + event.data.id);
        var beforeValue = obj.val();
        var bUpperLimit = false;

        var spanCode = String.Format('<span id= "SpellCeckSpan" style= "visibility:hidden;border:0;padding:0;font-size:{0};"></span>', obj.css("font-size"));
        obj.after(spanCode);
        var tmpSpanObj = $("#SpellCeckSpan");
        bUpperLimit = spellCeck(beforeValue + beforeValue.substr(beforeValue.length - 1), event.data.bTextarea, obj, tmpSpanObj);
        tmpSpanObj.remove();

        var selectedStr = getSelectedText(event.data.id);
        if (bUpperLimit && !selectedStr) {
            if (document.all) {
                window.event.returnValue = false;
                return false;
            } else {
                arguments.callee.caller.arguments[0].preventDefault();
                return true;
            }
        }
        else {
            setTimeout(function () { checkPasteTextWidth(event.data.id, event.data.bTextarea); }, 0);
        }
    }

    function FgClick(event) {
        setTimeout(function () { $("#" + event.data.id).focus(); }, 0);
    }

    function getLocation(elmid) {
        var elm = document.getElementById(elmid);
        if (elm.createTextRange) {
            // IE
            var range = document.selection.createRange();
            range.setEndPoint('StartToStart', elm.createTextRange());
            return range.text.length;
        } else if (typeof elm.selectionStart == 'number') {
            // Firefox
            return elm.selectionStart;
        }
    }

    function setLocation(elmid, n) {
        var elm = document.getElementById(elmid);
        if (n > elm.value.length)
            n = elm.value.length;
        if (elm.createTextRange) {
            // IE 
            var textRange = elm.createTextRange();
            textRange.moveStart('character', n);
            textRange.collapse();
            textRange.select();
        } else if (elm.setSelectionRange) {
            // Firefox 
            elm.setSelectionRange(n, n);
            elm.focus();
        }
    }
    function getCursorPosition(textarea) {
        var pos = 0;
        textarea.focus();
        if (textarea.setSelectionRange) {
            // W3C
            pos = textarea.selectionStart;
        } else if (document.selection) {
            // IE
            var i,
        oS = document.selection.createRange(),
        oR = document.body.createTextRange();
            oR.moveToElementText(textarea);

            for (i = 0; oR.compareEndPoints('StartToStart', oS) < 0 && oS.moveStart("character", -1) !== 0; i++) {
                if (textarea.value.charAt(i) == '\n') {
                    i++;
                }
            }
            pos = i;
        }
        return pos;
    }
    function setCursorPosition(textarea, pos) {
        if (textarea.setSelectionRange) {
            // W3C
            textarea.focus();
            textarea.setSelectionRange(pos, pos);
        } else if (textarea.createTextRange) {
            // IE
            var oR = textarea.createTextRange();
            // Fixbug :        
            // In IE, if cursor position at the end of textarea, the setCursorPosition function don't work        
            if (textarea.value.length === pos) {
                oR.collapse(false);
                oR.select();
            } else {
                oR.select();
            }
        }
    }

    function TextareaFocus(event) {
        var obj = $("#" + event.data.id);
        if (event.data.bReadOnly) {
            if (!event.data.bSpellCheck) {
                obj.removeClass("fwr_form_textarea_none_border");
            }
            return;
        }

        //将其z-index修改为fwr_form_widget_comboxlist
        obj.removeClass("fwr_form_widget").addClass("fwr_form_widget_comboxlist");
        $("#" + event.data.bgid).removeClass("fwr_form_widget").addClass("fwr_form_widget_comboxlist");

        if (FXREADER.g_pFormPlugin.m_bHighlight) {
            $("#" + event.data.fgid).css("display", "none");
            if (!event.data.bSpellCheck) {
                obj.removeClass("fwr_form_textarea_none_border");
            }
            obj.val(FXREADER.g_formValue.GetItemValue(obj.attr("name")));
        }
        else {
            var index = getCursorPosition(document.getElementById(event.data.id));
            if (!event.data.bSpellCheck) {
                obj.removeClass("fwr_form_textarea_none_border");
            }
            obj.val(FXREADER.g_formValue.GetItemValue(obj.attr("name")));
            setCursorPosition(document.getElementById(event.data.id), index);
        }
    }
    function TextareaBlur(event) {
        var obj = $("#" + event.data.id);
        if (event.data.bReadOnly) {
            obj.addClass("fwr_form_textarea_none_border");
            return;
        }

        //将其z-index修改为form_widget
        obj.removeClass("fwr_form_widget_comboxlist").addClass("fwr_form_widget");
        $("#" + event.data.bgid).removeClass("fwr_form_widget_comboxlist").addClass("fwr_form_widget");

        if (FXREADER.g_pFormPlugin.m_bHighlight) {
            $("#" + event.data.fgid).css("display", "");
        }
        obj.addClass("fwr_form_textarea_none_border");
        FXREADER.g_formValue.SetItemValue(obj.attr("name"), obj.val());
        if (obj.attr("noupdate") == "true") {
            obj.attr("noupdate", "");
        }
        else {
            Update(obj.attr("name"), obj.attr("id"));
        }
        obj.triggerJSAction();
    }
    function TextFocus(event) {
        var obj = $("#" + event.data.id);
        //将其z-index修改为fwr_form_widget_comboxlist
        obj.removeClass("fwr_form_widget").addClass("fwr_form_widget_comboxlist");
        $("#" + event.data.bgid).removeClass("fwr_form_widget").addClass("fwr_form_widget_comboxlist");

        if (FXREADER.g_pFormPlugin.m_bHighlight) {
            $("#" + event.data.fgid).css("display", "none");

            obj.attr("value", FXREADER.g_formValue.GetItemValue(obj.attr("name")));
        }
        else {
            var index = getLocation(event.data.id);
            obj.attr("value", FXREADER.g_formValue.GetItemValue(obj.attr("name")));
            setLocation(event.data.id, index);
        }
    }
    function TextBlur(event) {
        var obj = $("#" + event.data.id);
        //将其z-index修改为form_widget
        obj.removeClass("fwr_form_widget_comboxlist").addClass("fwr_form_widget");
        $("#" + event.data.bgid).removeClass("fwr_form_widget_comboxlist").addClass("fwr_form_widget");

        if (FXREADER.g_pFormPlugin.m_bHighlight) {
            $("#" + event.data.fgid).css("display", "");
        }

        FXREADER.g_formValue.SetItemValue(obj.attr("name"), obj.attr("value"));
        if (obj.attr("noupdate") == "true") {
            obj.attr("noupdate", "");
        }
        else {
            Update(obj.attr("name"), obj.attr("id"));
        }
        obj.triggerJSAction();
    }
    //Combo
    function SelectComboItem(jquer_obj, bSelected) {
        if (bSelected && (jquer_obj.attr("selected") != "1")) {
            jquer_obj.attr("selected", "1").addClass("fwr_form_listitem_selected");
        }
        else if ((!bSelected) && (jquer_obj.attr("selected") != "0")) {
            jquer_obj.attr("selected", "0").removeClass("fwr_form_listitem_selected");
        }
    }

    function ComboButFocusOrFgFocus(event) {
        setTimeout(function () { $("#" + event.data.inputid).focus(); }, 0);
    }
    function ComboButFocusOrFgClick(event) {
        setTimeout(function () { $("#" + event.data.inputid).focus().click(); }, 0);
    }

    function ComboButIputFocus(event) {
        //将其z-index修改为form_widget_comboxlist
        $("#" + event.data.id).removeClass("fwr_form_widget").addClass("fwr_form_widget_comboxlist");
        $("#" + event.data.bgid).removeClass("fwr_form_widget").addClass("fwr_form_widget_comboxlist");
        $("#" + event.data.inputid).removeClass("fwr_form_widget").addClass("fwr_form_widget_comboxlist");

        if (FXREADER.g_pFormPlugin.m_bHighlight) {
            $("#" + event.data.fgid).css("display", "none");
        }
    }
    function ComboButIputClick(event) {
        $("#" + event.data.listdivid).show();
    }

    function ComboButIputBlur(event) {
        setTimeout(function () {
            if (!document.activeElement.id ||
            (trim(document.activeElement.id).toLowerCase() != trim(event.data.inputid).toLowerCase() &&
            trim(document.activeElement.id).toLowerCase() != trim(event.data.id).toLowerCase() &&
            trim(document.activeElement.id).toLowerCase().indexOf(trim(event.data.id).toLowerCase()) == -1)) {
                var combobutobj = $("#" + event.data.id);
                var inputObj = $("#" + event.data.inputid);
                var inputRealValue = inputObj.attr("realValue");
                if (inputObj.val() != inputObj.attr("oldValue")) {
                    inputRealValue = inputObj.val();
                }
                FXREADER.g_formValue.SetItemValue(combobutobj.attr("name"), inputRealValue);
                Update(combobutobj.attr("name"));
                $("#" + event.data.listdivid).hide();

                //将其z-index修改为form_widget
                $("#" + event.data.id).removeClass("fwr_form_widget_comboxlist").addClass("fwr_form_widget");
                $("#" + event.data.bgid).removeClass("fwr_form_widget_comboxlist").addClass("fwr_form_widget");
                $("#" + event.data.inputid).removeClass("fwr_form_widget_comboxlist").addClass("fwr_form_widget");

                if (FXREADER.g_pFormPlugin.m_bHighlight) {
                    $("#" + event.data.fgid).css("display", "");
                }
            }
        }, 0);
    }

    function ComboListItemClick(event) {
        var curobj = $("#" + event.data.id);
        if (curobj.attr("selected") == '1') {
            return;
        }

        var combobutobj = $("#" + event.data.combodivid);
        FXREADER.g_formValue.SetItemValue(combobutobj.attr("name"), curobj.attr("realValue"));
        Update(combobutobj.attr("name"));
        $(event.target).trigger("blur");
    }
    //List
    function getX(obj) {
        var ParentObj = obj;
        var left = obj.offsetLeft;
        while (ParentObj = ParentObj.offsetParent) {
            if (ParentObj.offsetLeft < 0) {
                continue;
            }
            left += ParentObj.offsetLeft;
        }
        return left;
    }

    function getY(obj) {
        var ParentObj = obj;
        var top = obj.offsetTop;
        while (ParentObj = ParentObj.offsetParent) {
            if (ParentObj.offsetTop < 0) {
                continue;
            }
            top += ParentObj.offsetTop;
        }
        return top;
    }
    function ListboxFgClick(event) {
        var oDiv = document.getElementById(event.data.id);
        var pane = $('.scroll-pane');
        var api = pane.data('jsp');
        //var left = (event.clientX - getX(oDiv) + api.getContentPositionX()) - 2;
        var top = (event.clientY - getY(oDiv) + api.getContentPositionY()) - 2;

        var clickid = "";
        if (event.data.optiosCount > 0) {
            var listObj = $("#" + event.data.id);
            var listItemObjId = event.data.id + "_0";
            var itemHeight = parseFloat($("#" + listItemObjId).css("height"));
            if (!itemHeight) {
                //IE7\IE8
                itemHeight = parseFloat(document.getElementById(listItemObjId).scrollHeight);
            }

            var index = parseInt((top + listObj.scrollTop()) / itemHeight) + 1;
            if ((0 < index) && (index <= event.data.optiosCount)) {
                clickid = event.data.id + "_" + (index - 1);
            }
        }

        setTimeout(function () {
            $("#" + event.data.id).focus();
            if (clickid && clickid != "") {
                g_bFgClickAndCtrlKey = event.ctrlKey;
                $("#" + clickid).click();
            }
        }, 0);
    }
    function ListFocus(event) {
        //将其z-index修改为form_widget_comboxlist
        var obj = $("#" + event.data.id);
        obj.removeClass("fwr_form_widget").addClass("fwr_form_widget_comboxlist");
        obj.children().each(function () {
            $(this).removeClass("fwr_form_widget").addClass("fwr_form_widget_comboxlist");
        });
        $("#" + event.data.bgid).removeClass("fwr_form_widget").addClass("fwr_form_widget_comboxlist");

        if (FXREADER.g_pFormPlugin.m_bHighlight) {
            $("#" + event.data.fgid).css("display", "none");
        }
    }
    function ListBlur(event) {
        setTimeout(function () {
            var index = -1;
            if (document.activeElement.id) {
                var focusObjID = trim(document.activeElement.id).toLowerCase();
                var listObjID = trim(event.data.id).toLowerCase();
                index = focusObjID.lastIndexOf(listObjID);
            }
            if (index < 0) {
                //将其z-index修改为form_widget
                var obj = $("#" + event.data.id);
                obj.removeClass("fwr_form_widget_comboxlist").addClass("fwr_form_widget");
                obj.children().each(function () {
                    $(this).removeClass("fwr_form_widget_comboxlist").addClass("fwr_form_widget");
                });
                $("#" + event.data.bgid).removeClass("fwr_form_widget_comboxlist").addClass("fwr_form_widget");

                if (FXREADER.g_pFormPlugin.m_bHighlight) {
                    $("#" + event.data.fgid).css("display", "");
                }
            }
        }, 0);
    }

    var g_bFgClickAndCtrlKey = false;
    function ListItemClick(event) {
        //在FgClick触发该事件时，是否按了Ctrl
        var bCtrlKey = g_bFgClickAndCtrlKey;
        g_bFgClickAndCtrlKey = false;
        var curObj = $("#" + event.data.id);
        var listObj = $("#" + event.data.listdivid);
        var bMultiple = listObj.attr("multiple") == "true" ? true : false;
        var bCurObjSelected = curObj.attr("selected") == '1' ? true : false;
        var selectedObjValue = curObj.attr("realValue");

        if (!bMultiple && bCurObjSelected) {
            return;
        }
        else {
            listObj.children().each(function () {
                if (bMultiple && (event.ctrlKey || bCtrlKey)) {
                    if ($(this).attr("realValue") == selectedObjValue) {
                        SelectComboItem($(this), !bCurObjSelected);
                    }
                }
                else {
                    SelectComboItem($(this), $(this).attr("realValue") == selectedObjValue);
                }
            });

            var value = "";
            listObj.children().each(function () {
                if ($(this).attr("selected") == "1") {
                    if (value != "") {
                        value += ";";
                    }
                    value += trim($(this).attr("realValue"));
                }
            });
            FXREADER.g_formValue.SetItemValue(listObj.attr("name"), value);
            Update(listObj.attr("name"));
        }
    }

    function ListItemKeydown(event) {
        var curObj = $("#" + event.data.id);
        var listObj = $("#" + event.data.listdivid);
        var selectObj = null;
        var keyValue = event.keyCode || event.which;
        if (keyValue == 38) {
            //向上键
            selectObj = curObj.prev();
        }
        else if (keyValue == 40) {
            //向下键
            selectObj = curObj.next();
        }

        if (selectObj && selectObj.attr("tagName")) {
            FXREADER.g_formValue.SetItemValue(listObj.attr("name"), selectObj.attr("realValue"));
            Update(listObj.attr("name"));
            selectObj.focus();
        }
        return false;
    }

    function ListKeydown(event) {
        var firstObj = null;
        var selectedObj = null;
        var bPre = false;
        var keyValue = event.keyCode || event.which;
        if (keyValue == 38) {
            //向上键
            bPre = true;
        }
        else if (keyValue == 40) {
            //向下键
            bPre = false;
        }
        else {
            return false;
        }
        ////获取被选中的对象
        var listObj = $("#" + event.data.id);
        listObj.children().each(function () {
            if (!firstObj) {
                firstObj = $(this);
            }
            if (!selectedObj) {
                if ($(this).attr("selected") == '1') {
                    selectedObj = $(this);
                }
            }
            if (firstObj && selectedObj) {
                return false;
            }
        });


        //计算将要被选中的对象
        var selectObj;
        if (selectedObj) {
            if (bPre) {
                //向上键
                selectObj = selectedObj.prev();
            }
            else {
                //向下键
                selectObj = selectedObj.next();
            }
            if (selectObj && !selectObj.attr("tagName")) {
                selectObj = selectedObj;
            }
        }
        else {
            selectObj = firstObj;
        }
        /////选择改变，同时清除其他选择
        if (selectObj) {
            FXREADER.g_formValue.SetItemValue(listObj.attr("name"), selectObj.attr("realValue"));
            Update(listObj.attr("name"));
        }
        return false;
    }
    /////////////////////////////////////////////////////////////////////////////////表单控件消息处理 End

    FXREADER.FormPage = FormPage;
    FXREADER.FormValue = FormValue;
});
